home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / libelf-0.5 / libelf-0 / libelf-0.5.2 / cntl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  1.7 KB  |  68 lines

  1. /*
  2. cntl.c - implementation of the elf_cntl(3) function.
  3. Copyright (C) 1995 Michael Riepe <riepe@ifwsn4.ifw.uni-hannover.de>
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #include <private.h>
  21.  
  22. int
  23. elf_cntl(Elf *elf, Elf_Cmd cmd) {
  24.     Elf_Scn *scn;
  25.     Elf *child;
  26.  
  27.     if (!elf) {
  28.     return -1;
  29.     }
  30.     elf_assert(elf->e_magic == ELF_MAGIC);
  31.     if (elf->e_disabled) {
  32.     return 0;
  33.     }
  34.     if (cmd == ELF_C_FDREAD) {
  35.     if (!elf->e_readable) {
  36.         seterr(ERROR_WRONLY);
  37.         return -1;
  38.     }
  39.     if (!elf->e_size) {
  40.         return 0;
  41.     }
  42.     if (!elf->e_ehdr && !_elf_cook(elf)) {
  43.         return -1;
  44.     }
  45.     for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
  46.         if (scn->s_index == SHN_UNDEF || scn->s_type == SHT_NULL) {
  47.         continue;
  48.         }
  49.         else if (!elf_getdata(scn, NULL)) {
  50.         return -1;
  51.         }
  52.     }
  53.     }
  54.     else if (cmd != ELF_C_FDDONE) {
  55.     seterr(ERROR_INVALID_CMD);
  56.     return -1;
  57.     }
  58.     elf->e_disabled = 1;
  59.     for (child = elf->e_members; child; child = child->e_link) {
  60.     elf_assert(elf->e_kind == ELF_K_AR);
  61.     elf_assert(elf == child->e_parent);
  62.     if (elf_cntl(child, cmd)) {
  63.         return -1;
  64.     }
  65.     }
  66.     return 0;
  67. }
  68.